<?php
use \Workerman\Autoloader;

require_once __DIR__ . '/../../../../../Workerman/Autoloader.php';
require_once __DIR__.'/../../../Config/Const.php';
Autoloader::setRootPath(__DIR__.'/../../..');

$page_groupId = GROUP_NURSERY_STOCK_MN;
$page_pageId = PAG_NURSERY_STOCK_SPECIES_ADD;

require "../framepages/moudle_base.php";


$mode = $_GET['mode'];
$result = 'normal';
if ($mode == 'species_add') {

    $species_name = $_GET['species_name'];
    $species_group_name = $_GET['species_group_name'];
    $goods_name = $_GET['species_group_name'];

    $price = $_GET['price'];

    $province = $_GET['province_belo'];
    $city = $_GET['city_belo'];
    $county = $_GET['county_belo'];


    $year = $_GET['year'];
    $month = $_GET['month'];
    echo $province.$city.$county.$year.$month.$price;

    $species_record = new \Data\Nursery_stock_species(array());
    $species_record->setSPECIES_NAME($species_name);

    $species_id = \Data\Nursery_stock_species_DAO::insert($species_record);

    $species_group_record = new \Data\Nursery_stock_species_group(array());
    $species_group_record->setSPECIES_ID($species_id);
    $species_group_record->setSPECIES_GROUP_NAME($species_group_name);
    $species_group_id = \Data\Nursery_stock_species_group_DAO::insert($species_group_record);

    $goods_record = new \Data\Nursery_stock_goods(array());
    $goods_record->setSPECIES_GROUP_ID($species_group_id);
    $goods_record->setGOODS_NAME($goods_name);
    $goods_record->setPRICE($price);
    $goods_record->setPROVINCE($province);
    $goods_record->setCITY($city);
    $goods_record->setCOUNTY($county);
    \Data\Nursery_stock_goods_DAO::insert($goods_record);

    $result = 'succ_add_species';
}


?>
<div class="main-content">

        <table style="border-collapse: separate;border-spacing: 0 10px">
            <tr>
                <td>花木名称：</td>
                <td><input type="text" id="species_name" name="species_name" placeholder="例：白蜡"><td>
            </tr>
            <tr>
                <td>规格范围：</td>
                <td><input type="text" id="species_group_name" name="species_group_name" placeholder="例：胸径3-8cm"><td>
            </tr>
            <tr>
                <td>规格：</td>
                <td><input type="text" id="good_name" name="good_name" placeholder="例：胸径3cm"><td>
            </tr>
            <tr>
                <td>价格：</td>
                <td><input type="text" id="price" name="price" placeholder="20.55"><td>
            </tr>
            <tr>
                <td>年份：</td>
                <td><input type="text" id="year" name="year" value="<?php echo DATE('Y'); ?>"><td>
            </tr>

            <tr>
                <td>月份：</td>
                <td><input type="text" id="month" name="month" value="<?php echo (int)DATE('m'); ?>"><td>
            </tr>

        </table>


        <div class="container">
            <h5 class="title">请选择地区</h5>
            <div class="info">
                <select name="province" id="province">
                    <option value="">省份</option>
                </select>
                <select name="city" id="city">
                    <option value="">地级市</option>
                </select>
                <select name="county" id="county">
                    <option value="">市、县级市</option>
                </select>
            </div>
        </div>

        <br>
        <br>
        <div class="btn-toolbar list-toolbar">
            <button class="btn btn-danger" onclick="submit_add_species()">提交</button>

        </div>
</div>
</div>

<script src="../lib/location.js"></script>

<script src="../lib/bootstrap/js/bootstrap.js"></script>
<script>
    function init() {
        var msg = '<?php echo $result ?>';
        if (msg == 'succ_add_species') {
            alert('添加成功');
        }

        var pro=$("#province");
        for(var i=0;i<province.length;i++){
            var $temp=$("<option value=\"\">"+province[i].name+"</option>");
            pro.append($temp);
        }
    }

    function submit_add_species() {
        var province_belo = $("#province option:selected").text();  //获取选中的项
        var city_belo = $("#city option:selected").text();  //获取选中的项
        var county_belo = $("#county option:selected").text();  //获取选中的项

        var year = document.getElementById('year').value;
        var month = document.getElementById('month').value;
        var price = document.getElementById('price').value;

        url = "?mode=species_add&province_belo="+province_belo+"&city_belo="+city_belo+"&county_belo="+county_belo+
            "&year="+year+"&month="+month+"&price="+price;
        window.location.href = url;
    }

    $(function(){
        var pro=$("#province");
        var city=$("#city");
        var dAC=$("#county");
        var num1=null;
        var num2=null;
        //init();

        pro.change(function(){
            num1=pro.prop("selectedIndex");
            city.find("option").eq(0).siblings().remove();
            dAC.find("option").eq(0).siblings().remove();
            if(num1!==0){
                for(var i=0;i<province[num1-1].city.length;i++){
                    var $temp=$("<option value=\"\">"+province[num1-1].city[i].name+"</option>");
                    city.append($temp);
                }
            }
        });

        city.change(function(){
            num2=city.prop("selectedIndex");
            dAC.find("option").eq(0).siblings().remove();
            if(num2!==0){
                for(var i=0;i<province[num1-1].city[num2-1].districtAndCounty.length;i++){
                    var $temp=$("<option value=\"\">"+province[num1-1].city[num2-1].districtAndCounty[i]+"</option>");
                    dAC.append($temp);
                }
            }
        })
    });

</script>





